package com.yeebo.enums;

/**
 * 统一封装返回前端code枚举类
 */
public enum ResultCode {
    SUCCESS(0, "成功"),
    SYS_USER_NOT_EXIST(8000, "管理员账号不存在"),
    SYS_PASSWORD_NOT_MATCH(8001, "管理员账号密码不匹配"),
    SYS_USER_ACCOUNT_REPEAT(8002, "登录账号重复"),
    SYS_ROLE_CODE_REPEAT(8003, "角色编码重复"),
    RESOURCE_HAVE_CHILDREN(8004, "有资源依赖于该条资源，无法直接删除"),
    CAN_NOT_DELETE_MYSELF(8005, "不能删除当前登录账号"),
    CAN_NOT_DELETE_ADMIN(8006, "禁止删除管理员"),
    CAN_NOT_DELETE_SUPER_ROLE(8007, "禁止删除管理员角色"),
    RESOURCE_CODE_REPEAT(8008, "资源编码重复"),
    EXIST_SAME_GLOBAL_PARAM(8009, "已有重复的全局变量数据"),
    NEED_LOGIN(9995, "需要重新登录"),
    PERMISSION_DENY(9996, "您没有此项操作权限"),
    PARAM_MISS(9997, "参数缺失"),
    REPEAT_REQUEST(9998, "禁止重复提交"),
    ERROR(9999, "失败");

    private int code;
    private String message;

    ResultCode(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public static String getMsgByCode(int code) {
        for (ResultCode resultCode : ResultCode.values()) {
            if (resultCode.getCode() == code) {
                return resultCode.getMessage();
            }
        }
        return null;
    }
}
